package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Heartmark;
import cn.hl.sfzy.service.HeartmarkService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/heartmark")
public class HeartmarkController {
    @Autowired
    private HeartmarkService heartmarkService;
    @GetMapping("/find")
    public Result find(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize,
            Heartmark heartmark
    ){
        PageInfo<Heartmark> bypage =heartmarkService.findBypage(pageNum, pageSize,heartmark);
        Result result=Result.success(bypage);
        return result;
    }
    @PutMapping("/update")
    public Result update(@RequestBody Heartmark heartmark){
        int update = heartmarkService.update(heartmark);
        return Result.success(heartmark);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Heartmark heartmark){
        System.out.println(heartmark.toString());
        System.out.println(heartmark);
        int i = heartmarkService.add(heartmark);
        return Result.success(heartmark);
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        System.out.println(id);
        heartmarkService.deleteById(id);
        return Result.success("删除成功");
    }


}
